<template>
  <div>
    <cus-modal
      ref="modal"
      title="上报配置"
      width="650"
      @onOk="onOk"
    >
      <Form
        ref="formValidate"
        :model="configForm"
        :label-width="120"
        inline
      >
        <FormItem v-for="item in configData" :label="item.nameDescr">
          <Select v-model="item.paramValue" style="width: 200px">
            <Option v-for="it in item.valueList" :value="it.value" :key="it.value">{{
              it.option
            }}</Option>
          </Select>
          <div :class="item.valueDescr.length > 18 ? '' : 'descr'">
            {{item.valueDescr}}
          
          </div>
        </FormItem>
        <Spin size="large" fix v-if="modelLoading"></Spin>
      </Form>
    </cus-modal>
   
  </div>
</template>

<script>
import { getSystemConfigList,editSystemConfigList } from "@/api/organ/organization";
export default {
  data() {
    return {
      configForm: {
        model: "",
      },
      modelLoading: false,
      configData: {},
    };
  },
  methods: {
    show(row) {
      console.log(row);
      this.getSystemConfigListApi(row);
      this.$refs["modal"].show = true;
    },
    onOk() {
      this.modelLoading = true
      this.editSystemConfigListApi()
    },
    // 获取单位所有单位配置
    getSystemConfigListApi(row) {
      this.modelLoading = true
      return new Promise((resolve) => {
        getSystemConfigList({
          unitCode: row.unitCode,
        }).then((res) => {
          if (res.code == 1) {
            res.data.forEach(item => {
              if(item.valueItems) {
                item.valueList = JSON.parse(item.valueItems)
              }
            });
            this.configData = res.data;
             console.log('',this.configData);
          }
          this.modelLoading = false;
        });
      });
    },
    // 修改单位配置
    editSystemConfigListApi() {
      return new Promise((reslove) => {
        editSystemConfigList(
          {
            systemConfigEditList: this.configData
}
        ).then((res) => {
          if(res.code == 1) {
            this.$Message.success('修改成功')
            this.modelLoading = false;
            this.$refs["modal"].show = false;
          }
          this.modelLoading = false;
           
          
        })
      })
    }
  },
};
</script>

<style scoped lang="scss">
  .descr{
    float: right;
    margin-left: 10px;

  }
</style>
